package dao

import (
	"go/models"
)

func AddSC(sc models.Sc) error {
	// err := db.Table("student_message").Select("sno", "sname", "ssex", "sage", "sdept", "sedu_sys", "sregion", "spolitics", "snation").Create(&student).Error
	err := db.Table("sc").Create(&sc).Error
	return err
}

func DelSC(sno int) error {
	err := db.Table("sc").Where("sno = ?", sno).Update("is_del", true).Error
	return err
}

func UpdateSC(sc models.Sc) error {
	sno := sc.Sno
	cno := sc.Cno
	err := db.Table("sc").Where("sno = ? and cno = ?", sno, cno).Updates(&sc).Error
	return err
}

func GetSC(scParam map[string]interface{}) ([]models.Sc, int64, error) {
	var scData []models.Sc
	page := scParam["page"].(int)
	pageSize := scParam["limit"].(int)
	searchName := scParam["searchName"].(string)
	var total int64
	err := db.Table("sc").Where("sno like ? AND is_del = false", searchName+"%").Order("sno ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&scData).Error
	return scData, total, err
}
